﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FacturIT.Service.Repositories.WorkinhgHour;
using FacturIT.Service.WorkingHour;

namespace FacturIT.Service.WorkingHour
{
    internal class WorkingHourFactory
    {
        private static WorkingHourFactory instance = null;
        public static WorkingHourFactory Instance
        {
            get
            {
                if (instance == null)
                    instance = new WorkingHourFactory();
                return instance;
            }
        }

        private WorkingHourervice WorkingHourervice;
        public WorkingHourervice GetWorkingHourervice()
        {
            if (WorkingHourervice == null)
                WorkingHourervice = new WorkingHourervice();

            return WorkingHourervice;
        }
    }
    internal class WorkingHourervice
    {
        private IRepository<BLL.Model.WorkingHour.WorkingHour, int> repository;
        private IRepository<BLL.Model.WorkingHour.WorkingHour, int> Repository
        {
            get
            {
                if (repository == null)
                    repository = new WorkingHourRepository();

                return repository;
            }
        }

        internal WorkingHourDTO AddWorkingHour(int companyProjectID, DateTime starttime, DateTime endtime, bool charged)
        {
            WorkingHourDTO WorkingHour = Convert(Repository.Add(new BLL.Model.WorkingHour.WorkingHour()
            {
                CompanyProjectID = companyProjectID,
                StartTime = starttime,
                EndTime = endtime,
                Charged = charged
            }));
            return WorkingHour;
        }

        internal IEnumerable<WorkingHourDTO> ReadAllMyTotalWorkingHoursForProject(int companyProjectID)
        {
            return from wh in ((WorkingHourRepository)Repository).ReadAllMyTotalWorkingHoursForProject(companyProjectID) select new WorkingHourDTO(wh);
        }

        internal IEnumerable<WorkingHourDTO> ReadTotalWorkingHoursForProject(int projectID)
        {
            return from wh in ((WorkingHourRepository)Repository).ReadTotalWorkingHoursForProject(projectID) select new WorkingHourDTO(wh);
        }

        internal IEnumerable<WorkingHourDTO> ReadMyTotalChargedForProject(int companyProjectID)
        {
            return from wh in ((WorkingHourRepository)Repository).ReadMyTotalChargedForProject(companyProjectID) select new WorkingHourDTO(wh);
        }
        internal IEnumerable<WorkingHourDTO> ReadAllWorkingHoursFromUserProjectInPeriodAndSetCharged(int companyprojectid, DateTime van, DateTime tot)
        {
            return from wh in ((WorkingHourRepository)Repository).ReadAllWorkingHoursFromUserProjectInPeriodAndSetCharged(companyprojectid, van, tot) select new WorkingHourDTO(wh);
        }
        internal IEnumerable<WorkingHourDTO> ReadAllWorkingHoursFromUserProjectInPeriodCharged(int companyprojectid, DateTime van, DateTime tot)
        {
            return from wh in ((WorkingHourRepository)Repository).ReadAllWorkingHoursFromUserProjectInPeriodCharged(companyprojectid, van, tot) select new WorkingHourDTO(wh);
        }
        #region HelperMethods

        private static WorkingHourDTO Convert(BLL.Model.WorkingHour.WorkingHour WorkingHour)
        {
            return new WorkingHourDTO(WorkingHour);
        }
        #endregion











        
    }
}